new Vue({
    el: '#app',
    data() {
      return {
        form: {
          page: 1,			//页数
          limit: 10,		//每页数据条数
          Enterprise_Info_SerialNumber:$.cookie("enterprise")
        },
        formData: {},
        tableData: [],
        tableData2: [],
        //表格数据
        total: 1,
        dialogForm: false,
        title: '',
        multipleSelection: []
      }
    },
    mounted() {
      this.getList(this.form)
      console.log(DomainName);
      console.log(absolutepath());
    },
    methods: {
      onSerach() {				//查询方法
        this.getList(this.form)
      },
      addContract() {
        console.log("跳转")
      },
      handleSizeChange(val) {
        this.form.page = 1;
        this.form.limit = val;
        this.getList(this.form)
      },
      handleCurrentChange(val) {
        this.form.page = val;
        this.getList(this.form)
      },
      getList(data) {
        let _this = this
        $.ajax({
          type: 'POST',
          data,
          url: DomainName2 + '/getInventoryInfoAction?token=' + $.cookie("token"),
          success: function (data) {
            _this.tableData = data.tableData;
            _this.total = Number(data.limit);
            console.log(_this.tableData)
          },
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
          dataType: "json"
        });
      },
      expandChange(row) {
        let data = row.Sales_Inventory_SerialNumber
        let _this = this
        $.ajax({
          type: 'POST',
          data: {
            Sales_Inventory_SerialNumber: data
          },
          url: DomainName + '/getInventoryArticleInfoAction?token=' + $.cookie("token"),
          success: function (data) {
            // row.Children.sales_article_inventory = data.Data;
            _this.$set(row.Children,'sales_article_inventory',data.Data)
            console.log('row.Children.sales_article_inventory',row.Children.sales_article_inventory);
          },
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
          dataType: "json"
        });
      },
      addEnterprise() {
        window.location.href = './Add.html'
      },
      showMember(Sales_Unit_Price_SerialNumber) {
        sessionStorage.setItem("Sales_Unit_Price_SerialNumber", Sales_Unit_Price_SerialNumber)
        window.location.href = './show.html?Sales_Unit_Price_SerialNumber=' + Sales_Unit_Price_SerialNumber
      },
      editMember(Sales_Unit_Price_SerialNumber) {
        sessionStorage.setItem("Sales_Unit_Price_SerialNumber", Sales_Unit_Price_SerialNumber)
        window.location.href = './Edit.html?Sales_Unit_Price_SerialNumber=' + Sales_Unit_Price_SerialNumber
      },
      onExcel() {
        /* generate workbook object from table */
        //  .table要导出的是哪一个表格
        var wb = XLSX.utils.table_to_book(document.querySelector("#out-table"));
        /* get binary string as output */
        var wbout = XLSX.write(wb, {
          bookType: "xlsx",
          bookSST: true,
          type: "array"
        });
        try {
          //  name+'.xlsx'表示导出的excel表格名字
          saveAs(
            new Blob([wbout], {
              type: "application/octet-stream"
            }),
            "无货商品库存" + ".xlsx"
          );
        } catch (e) {
          if (typeof console !== "undefined") console.log(e, wbout);
        }
        return wbout;
      },
      deletMember(Sales_Inventory_SerialNumber) {
        this.$confirm('此操作将作废该无货商品库存, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          this.delete(Sales_Inventory_SerialNumber);
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      delete(Sales_Inventory_SerialNumber) {
        const _this = this
        $.ajax({
          url: DomainName + '/DeleteAction?token=' + $.cookie("token"),
          type: 'POST',
          data: { 
            TableName: 'sales_inventory',
            Primary_Key:Sales_Inventory_SerialNumber,
            Primary_Key_Name:'Sales_Inventory_SerialNumber'
          },
          success: function (res) {
            if (res.Status == 'success') {
              _this.$message({
                type: 'success',
                message: '作废成功!'
              });
              _this.getList(_this.form)
            }
          }
        })
      },
      // 子表删除
      deletMember2(row) {
        const _this = this;
        let Primary_Key_Name = "Sales_Article_Inventory_SerialNumber";
        let Primary_Key = row.Sales_Article_Inventory_SerialNumber;
        this.$confirm('此操作将作废该无货商品库存, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          $.ajax({
            url: DomainName + '/DeleteAction?token=' + $.cookie("token"),
            type: 'POST',
            data: {
              TableName: 'sales_article_inventory',
              Primary_Key_Name,
              Primary_Key,
            },
            error: function (res) {
              console.log(res);
              _this.$message.error("删除失败，请稍后再试")
            },
            complete: function (XMLHttpRequest) {
              _this.loading = false
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            },
            success: function (res) {
              if (res.Status == 'success') {
                _this.$message({
                  type: 'success',
                  message: '作废成功!'
                });
                _this.getList(_this.form)
              }
            }
          })
        }).catch(() => {
          this.$message({
            type: 'warning',
            message: '已取消删除'
          });
        });
      },
    },
  })